﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WXY.Course.BLL;
using WXY.Course.Model;
using WXY.Course.Web.Areas.Admin.Filter;

namespace WXY.Course.Web.Areas.Admin.Controllers
{
    public class RecommendController : Controller
    {
        private RecommendBLL _recommendBLL = new RecommendBLL();

        //public ActionResult

        public ActionResult List()
        {
            var result = _recommendBLL.GetList();
            return View(result);
        }

        [HttpPost]
        [JsonExceptionFilter(typeof(RecommendController))]
        public JsonResult Add(string name, string url, int position, string image)
        {
            var info = new RecommendInfo
            {
                Name = name,
                Url = url,
                Position = (RecommendPosition)position,
                Image = image
            };
            var result = _recommendBLL.Insert(info);

            if (result > 0)
            {
                return Json(new { IsSuccess = true, Data = result });
            }

            return Json(new { IsSuccess = false, Message = "添加失败" });
        }

        [HttpPost]
        [JsonExceptionFilter(typeof(RecommendController))]
        public JsonResult Delete(int id)
        {
            int result = _recommendBLL.Delete(id);
            return Json(new { IsSuccess = result > 0, Data = result });
        }
    }
}
